| Conditions | 1 |
| Paths | 1 |
| Total Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | 'use strict'; |
||
| 16 | function($scope, $interval, $timeout, savegame, achievement, util, format, reaction, data, visibility, state) { |
||
| 17 | $scope.data = data; |
||
| 18 | $scope.achievement = achievement; |
||
| 19 | $scope.util = util; |
||
| 20 | $scope.format = format; |
||
| 21 | $scope.reaction = reaction; |
||
| 22 | $scope.visibility = visibility; |
||
| 23 | $scope.state = state; |
||
| 24 | |||
| 25 | let self = this; |
||
| 26 | let playerCopy = null; |
||
| 27 | |||
| 28 | self.update = function() { |
||
| 29 | // do the update in a copy |
||
| 30 | playerCopy = angular.copy(state.player); |
||
| 31 | achievement.checkAchievements(playerCopy); |
||
| 32 | |||
| 33 | state.update(playerCopy); |
||
| 34 | |||
| 35 | // and update all at once |
||
| 36 | state.player = playerCopy; |
||
| 37 | |||
| 38 | $timeout(self.update, 1); |
||
| 39 | }; |
||
| 40 | |||
| 41 | function save() { |
||
| 42 | localStorage.setItem('playerStoredITE', JSON.stringify(state.player)); |
||
| 43 | } |
||
| 44 | |||
| 45 | self.startup = function() { |
||
| 46 | savegame.load(); |
||
| 47 | state.loading = false; |
||
| 48 | $timeout(self.update, 1000); |
||
| 49 | $interval(save, 10000); |
||
| 50 | }; |
||
| 51 | |||
| 52 | $timeout(self.startup); |
||
| 53 | } |
||
| 54 | ]); |
||
| 55 |